{% extends 'base.html' %}
{% load staticfiles %}
{% block title %}
动态
{% endblock %}
{% block content %}
<div class="am-container">
    {% for say in says %}

    <div class="am-u-sm-12" style="margin-top: 10px;">
        <div class="am-panel am-panel-default">
            <div class="am-panel-hd">
                <strong><a href="/user/{{ say.user.key }}" style="color: {{ say.user.color }};">{{ say.user.username }}</a></strong>
                &nbsp;&nbsp;&nbsp;
                <span>{{ say.created_time }}</span>
            </div>
            <div class="am-comment-bd">
                {{ say.content|safe }}
            </div>
        </div>
    </div>


    {% endfor %}
</div>
{% if request.session.is_login and not request.session.is_forbidden %}
<div class="am-container">
    <div class="am-u-sm-12" style="margin-top: 10px;">
        <form action="{% url 'say_list' %}" method="POST">
            {% csrf_token %}
            <div id="editor"></div>
            <textarea type="text" name="text" id="text" style="display: none;"></textarea>
            <button type="submit" class="am-btn am-btn-primary am-radius" style="margin-top: 10px;">提交</button>
        </form>
        
    </div>
</div>
{% endif %}
<script src="//unpkg.com/wangeditor/release/wangEditor.min.js"></script>

<script>
var Editor = window.wangEditor
    var editor = new Editor('#editor')
    editor.customConfig.menus = [
        'bold',
        'italic',
        'underline',
        'strikeThrough',
        'link',
        'emoticon',
        'code',
        'undo', // 撤销
        'redo',
        'image',
    ]
    editor.customConfig.emotions = [
        {
            // tab 的标题
            title: 'emoji',
            // type -> 'emoji' / 'image'
            type: 'emoji',
            // content -> 数组
            content: ['😀', '😃', '😄', '😁', '😆','😂','😅','😎','😋','😊','😉','😐','😣','😥','🥰','😜','🤪','😡']
        }
    ]
    var $text = $('#text')
    setInterval("change();",10);
    function change(){
        $text.val(editor.txt.html());
    }
    editor.create()
    // 初始化 textarea 的值
    $text.val(editor.txt.html())
</script>
{% endblock %}